forvalues year = 3/19 {

	if `year' == 3 {
		local dir rvu0`year'_d
		local filename pprrvu03
		local sheetname pprrvu03
		local cellmax Z12710
	}
	
	if `year' == 4 {
		local dir rvu0`year'_d
		local filename pprrvu04r
		local sheetname pprrvu04
		local cellmax AA13094
	}
	
	if `year' == 5 { 
		local dir rvu0`year'_e
		local filename PPRRVU05
		local sheetname PPRRVU05
		local cellmax AA13278
	}
	
	if `year' == 6 { 
		local dir rvu0`year'd
		local filename PPRRVU06
		local sheetname PPRRVU06
		local cellmax AB13663
	}
	
	if `year' == 7 { 
		local dir rvu0`year'd
		local filename PPRRVU07
		local sheetname PPRRVU07
		local cellmax AK14426
	}	
	
	if `year' == 8 { 
		local dir rvu0`year'd
		local filename PPRRVU08
		local sheetname PPRRVU08
		local cellmax AK14659
	}
	
	if `year' == 9 { 
		local dir rvu0`year'd
		local filename PPRRVU09
		local sheetname PPRRVU09
		local cellmax AK14884
	}
	
	if `year' == 10 {
		local dir RVU10D_PCT22
		local filename PPRRVU10_OCT_PCT22_V6
		local sheetname PPRRVU10_OCT_PCT22_V6
		local cellmax AK15091
	}
	
	if `year' == 11 {
		local dir RVU`year'D
		local filename PPRRVU11_OCT_082511_v2
		local sheetname PPRRVU11
		local cellmax AK15042
	}
	
	if `year' == 12 { 
		local dir RVU`year'D
		local filename PPRRVU12
		local sheetname PPRRVU12_V0809
		local cellmax AK15471
	}
	
	if `year' == 13 { 
		local dir RVU`year'D
		local filename PPRRVU13_V0828
		local sheetname PPRRVU13_V0828
		local cellmax AE15646
	}
	
	if `year' == 14 {
		local dir RVU`year'D
		local filename PPRRVU14_V0815_v5
		local sheetname PPRRVU14_V0815_v4
		local cellmax AE15917
	}
	
	if `year' == 15 {
		local dir RVU`year'D
		local filename PPRRVU15_OCT_V1001
		local sheetname PPRRVU15_OCT_V1001
		local cellmax AE16100
	}
	
	if `year' == 16 {
		local dir rvu16d1
		local filename PPRRVU16_V0804
		local sheetname PPRRVU16_V0804
		local cellmax AE16333
	}
	
	if `year' == 17 {
		local dir rvu17d1
		local filename PPRRVU17_OCT
		local sheetname PPRRVU18_OCT_V0818
		local cellmax AE16508
	}
	
	if `year' == 18 {
		local dir rvu18d
		local filename PPRRVU18_OCT
		local sheetname PPRRVU18_V0815
		local cellmax AE16692
	}
	
	if `year' == 19 {
		local dir RVU`year'D
		local filename PPRRVU19_OCT
		local sheetname PPRRVU19_V0815
		local cellmax AE17056
	}
	
	if inrange(`year', 3, 9) 		loc excel_vers "xls"
	else 							loc excel_vers "xlsx"

	import excel "${raw_data}/RVU/`dir'/`filename'.`excel_vers'", sheet(`sheetname') cellrange(A11:`cellmax') clear	
	if inrange(`year', 3, 6) 			rename (A B F G I K L M) (hcpcs mod workrvu nonfacpervu facilitypervu mprvu nonfactotal facilitytotal) // Use fully-implemented for pre-2007 years
	else if inrange(`year', 7, 12) 		rename (A B F G K O P R) (hcpcs mod workrvu nonfacpervu facilitypervu mprvu nonfactotal facilitytotal)
	else if inrange(`year', 13, 19) 	rename (A B F G I K L M) (hcpcs mod workrvu nonfacpervu facilitypervu mprvu nonfactotal facilitytotal)

	gen year = 20`year'
	replace year = 200`year' if year < 2000
	
	keep year hcpcs mod workrvu nonfacpervu facilitypervu mprvu nonfactotal facilitytotal
	
	drop if mi(facilitytotal) & mi(nonfactotal)

	gen facilityWORKfrac = workrvu / facilitytotal
	gen facilityPEfrac = facilitypervu / facilitytotal
	gen facilityMPfrac = mprvu / facilitytotal
	gen nonfacWORKfrac = workrvu / nonfactotal
	gen nonfacPEfrac = nonfacpervu / nonfactotal
	gen nonfacMPfrac = mprvu / facilitytotal

	lab var facilitytotal "Total Facility RVUs"
	lab var facilityWORKfrac "Facility Work / tot RVU"
	lab var facilityPEfrac "Facility PE / tot RVU"
	lab var facilityMPfrac "Facility MP / tot RVU"
	lab var nonfactotal "Total Non-Fac RVUs"
	lab var nonfacWORKfrac "Non-Fac Work / tot RVU"
	lab var nonfacPEfrac "Non-Fac PE / tot RVU"
	lab var nonfacMPfrac "Non-Fac MP / tot RVU"
	
	gen code = ""
	replace code = hcpcs + "-" + mod if !mi(mod)
	replace code = hcpcs if mi(mod)
	
	sort code hcpcs mod
	keep year code hcpcs mod *total* *frac 
	order year code hcpcs mod *total* *frac
	duplicates drop

			
	tempfile RVU20`year'
	save "`RVU20`year''"
}

clear 

forvalues year = 3/19 {
	
	append using "`RVU20`year''"
	
}

save "${intermediate_data}/RVU/RVUvalues_appended.dta", replace
